<?php

/**
* alltosun.com 订单公用函数 order_helper.php
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 吴松键 (wusj@alltosun.com) $
* $Date: 2014-8-8 下午6:52:59 $
* $Id$
*/

class refund_helper
{
    public static function get_order_num_by_refund_status($refund_status = 0, $type = 0)
    {
        if (!$refund_status || !$type) {
            return 0;
        }

        return _model('refund')->getTotal(array('refund_status'=>$refund_status, 'type'=>$type, 'status'=>1));
    }
    /**
     * 通过退货单id获取退货信息
     * @param string $refund_id
     */
    public static function get_refund_relation_list($refund_id = '') {
        if (!$refund_id) {
            return false;
        }

        $refund_relation_list = _model('refund_relation')->getList(array('refund_id'=>$refund_id, 'status'=>1));

        foreach ($refund_relation_list as $k => $v) {
            $order_relation_info = array();
            $sku_snapshot_info = array();
            $goods_info = '';
            $order_relation_info = _uri('order_relation', $v['order_relation_id']);
            $sku_snapshot_info = _uri('sku_snapshot', $order_relation_info['sku_snapshot_id']);
            $goods_info = json_decode($sku_snapshot_info['goods_data'], true);

            $refund_relation_list[$k]['order_realtion_info'] = $order_relation_info;
            $refund_relation_list[$k]['sku_snapshot_info'] = $sku_snapshot_info;
            $refund_relation_list[$k]['goods_title'] = $goods_info['title'];
        }
        return $refund_relation_list;
    }

    /**
     * 获取退货总金额
     * @param string $refund_id
     * @return string
     */
    public static function get_refund_total_price($refund_id = '') {
        if (!$refund_id) {
            return false;
        }

        $refund_relation_list = _model('refund_relation')->getList(array('refund_id'=>$refund_id, 'status'=>1));

        $refund_total_price = '';
        foreach ($refund_relation_list as $k => $v) {
            $refund_total_price += $v['refund_num'] * $v['refund_price'];
        }
        return number_price($refund_total_price, 2);
    }
}
?>